package com.kgcx.organization.service;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.utils.CityUtils;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.Airport;
import com.kgcx.organization.mapper.AirportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AirportService {
    @Autowired
    private AirportMapper airportMapper;

    public Airport getAirport(Long kid) {
        return airportMapper.selectByPrimaryKey(kid);
    }

    public List<Airport> getAirportList(RequestData rd) {
        Airport airport = new Airport();
        airport.setCityId(CityUtils.getCityId(rd));
        PageUtils.page(rd);
        return airportMapper.selectActive(airport);
    }

    @Transactional(rollbackFor = Exception.class)
    public void addAirport(Airport airport) {
        airportMapper.insertSelective(airport);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateAirport(Airport airport) {
        airportMapper.updateByPrimaryKeySelective(airport);
    }

    @Transactional(rollbackFor = Exception.class)
    public void removeAirport(Long kid) {
        Airport airport = new Airport();
        airport.setKid(kid);
        airport.setStatus(Cons.COMMON_STATUS_DELETE);
        airportMapper.updateByPrimaryKeySelective(airport);
    }
}
